<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@ include file="/pages/common/header.jsp"%>
<script type="text/javascript">
var gridManager;
var _dialog;
$(function (){
	PageLoader.initSearchPanel();
	gridManager = PageLoader.initGridPanel();
});

PageLoader = {
 //
 initSearchPanel:function(){
 $("input[id^='executeTimeID_']").ligerDateEditor();//加载日期选择器
 },	
 initGridPanel:function(){
	 var g = $("#maingrid").ligerGrid({
         checkbox:true,
         height : '100%',
         rowHeight: 28,//行默认的高度
         headerRowHeight: 30,//表头行的高度
         pageSize : 20,
         onToNext:next,//条件查询方法
         columns: [
          { display: '预处理类型', name: 'executeName', width : 160, editor: { type: 'text' }},   
          { display: '开始时间', name: 'executeStartTime',width : 150,editor: { type: 'text' },
        	  	render:function(rowdata){
          		var s= rowdata.executeStartTime;
          		if(s==null){
          			return;
          		}
          		return s.replace("T"," ");
          }},   
          { display: '结束时间', name: 'executeEndTime',width : 150,editor: { type: 'text' },
      	  	render:function(rowdata){
        		var s= rowdata.executeEndTime;
        		if(s==null){
        			return;
        		}
        		return s.replace("T"," ");
        }}, 
        { display: '处理时间段', name: 'taskTime',width : 150,editor: { type: 'text' }
        },
        { display: '执行时间(S) ', name:'executeTotalTime',editor:{type:'text'},
       	 render:function(rowdata) {
       		 var s=rowdata.executeTotalTime;
       		 return s/1000;
       	 }
         },
          { display: '处理类型', name: 'executeType',editor: { type: 'text' },
        	  render:function(rowdata){
        		  var s=rowdata.executeType;
        		  if(s==null || s==0){
        			  return;
        		  }else if(s==1){
        			  return "开始处理";
        		  }else if(s==2){
        			  return "处理成功";
        		  }else if(s==3){
        			  return "处理出错";
        		  }
        	  }
        	  
          },     
          { display: '任务总数', name:'tasksNumber',editor:{type:'text'}},
          { display: '失败数', name:'failuresNumber',editor:{type:'text'}},
          { display: '插入数', name:'insertNumber',editor:{type:'text'}},
          { display: '操作',  width: 120, render: function (rowdata, rowindex, value)
            {
                var param = '"' + rowdata.id + '"';
                var h = "<a href='javascript:openDetailsPage(" + param + ")'>查看</a> ";
                return h;
            }
        }
        ], 
        enabledEdit: false, clickToEdit: false,  
        url:"<%=contextPath %>/preprocess-LogMessage-pageJson.action",
        width: '100%',
        toolbar: { items: [
          /*   { id: "add", text: '增加', click: itemclick, icon: 'add' },
	        { line: true },
	        { id: "modify", text: '修改', click: itemclick, icon: 'modify' },
            { line: true }, */
	        { id: "remove", text: '删除', click: itemclick, icon: 'delete' }
        ]
        }
    });
	 g.toggleCol("id",false);//隐藏id列
	 return g;
 }
}


//查询方法
function searchAction(){
     //form validate
   if(!Validator.Validate(document.getElementById("searchForm"),3))return;
//	var param=$("#searchForm").serialize();
	g = $("#maingrid").ligerGrid({
        checkbox:true,
        height : '100%',
        rowHeight: 28,//行默认的高度
        headerRowHeight: 30,//表头行的高度
        pageSize : 20,
        onToNext:next,//条件查询方法
        newPage:'1',
        columns: [
         { display: '预处理类型', name: 'executeName', width : 160, editor: { type: 'text' }},   
         { display: '开始时间', name: 'executeStartTime',width : 150,editor: { type: 'text' },
       	  	render:function(rowdata){
         		var s= rowdata.executeStartTime;
         		if(s==null){
         			return;
         		}
         		return s.replace("T"," ");
         }},   
         { display: '结束时间', name: 'executeEndTime',width : 150,editor: { type: 'text' },
     	  	render:function(rowdata){
       		var s= rowdata.executeEndTime;
       		if(s==null){
       			return;
       		}
       		return s.replace("T"," ");
       }}, 
       { display: '处理时间段', name: 'taskTime',width : 150,editor: { type: 'text' }
       },
       { display: '执行时间(S) ', name:'executeTotalTime',editor:{type:'text'},
      	 render:function(rowdata) {
      		 var s=rowdata.executeTotalTime;
      		 return s/1000;
      	 }
        },
         { display: '处理类型', name: 'executeType',editor: { type: 'text' },
       	  render:function(rowdata){
       		  var s=rowdata.executeType;
       		  if(s==null || s==0){
       			  return;
       		  }else if(s==1){
       			  return "开始处理";
       		  }else if(s==2){
       			  return "处理成功";
       		  }else if(s==3){
       			  return "处理出错";
       		  }
       	  }
       	  
         },     
         { display: '任务总数', name:'tasksNumber',editor:{type:'text'}},
         { display: '失败数', name:'failuresNumber',editor:{type:'text'}},
         { display: '插入数', name:'insertNumber',editor:{type:'text'}},
         { display: '操作',  width: 120, render: function (rowdata, rowindex, value)
           {
               var param = '"' + rowdata.id + '"';
               var h = "<a href='javascript:openDetailsPage(" + param + ")'>查看</a> ";
               return h;
           }
       }
       ], 
       enabledEdit: false, clickToEdit: false, 
       parms : [
         	   {name:"logMessageDTO.executeClass",value: $("#executeClassID").val()},
        	   {name:"logMessageDTO.executeName",value: $("#executeNameID").val()},
        	   {name:"logMessageDTO.executeStartTime",value: $("#executeTimeID_star").val()},
        	   {name:"logMessageDTO.executeTimeEnd",value: $("#executeTimeID_end").val()},
        	   {name:"logMessageDTO.executeType",value: $("#executeTypeID").val()}
                ],
       url:"<%=contextPath %>/preprocess-LogMessage-pageJson.action",
       width: '100%',
       toolbar: { items: [
	        { id: "remove", text: '删除', click: itemclick, icon: 'delete' }
       ]
       }
   });
	//gridManager.loadServerData(param);/*执行服务器查询*/
}

/*分页条件查询参数*/
function next(){
	gridManager.setOptions({
        parms: [
	   {name:"logMessageDTO.executeClass",value: $("#executeClassID").val()},
	   {name:"logMessageDTO.executeName",value: $("#executeNameID").val()},
	   {name:"logMessageDTO.executeStartTime",value: $("#executeTimeID_star").val()},
	   {name:"logMessageDTO.executeTimeEnd",value: $("#executeTimeID_end").val()},
	   {name:"logMessageDTO.executeType",value: $("#executeTypeID").val()},
       {}
        ]
    });
}

function itemclick(item)
{
	switch (item.id) {
		case "add":
			openFormDialog(false);
	        break;
		case "modify":
			openFormDialog(true);
	        break;
		case "remove":
			deleteAction();
	        break;
	}
}


function openDetailsPage(id){
	var url = "<%=contextPath %>/preprocess-LogMessage-view.action?id="+id;
	_dialog = jQuery.ligerDialog.open({
  	    title: '查看',
  	    url:url,
  	    isResize: true,
  	    width: 850, 
  	    height: 500, 
  	    isHidden: false
      });
}

function openFormDialog(edit){
	var url = "LogMessage-add.jsp";
	if(edit){
		var newRow = gridManager.getSelected();
	     if (!newRow) { alert('请选择行'); return; }
	     var i = 0;
	     $.each(gridManager.getCheckedRows(), function(index, element) {
			  i++;
		  });
	     if(i>1){
	    	 alert('请只选择一行'); return;
	     }
	     id = newRow.id;
	     url = "LogMessage-update.jsp?id=" + newRow.id;
	}
	_dialog = jQuery.ligerDialog.open({
  	    title: edit ? '编辑' : '新增',
  	    url:url,
  	    isResize: true, width: 550, height: 550, isHidden: false
      });
}

/*删除行*/
function deleteAction()
{ 
    var newRow = gridManager.getSelected();
    if (!newRow) { alert('请选择行'); return; }
    
    var removeData = '';
	  $.each(gridManager.getCheckedRows(), function(index, element) {
		  removeData = removeData + element.id + ',';
	  });
	  removeData = removeData.substr(0, removeData.length - 1) ;
    var data = [{ name: 'ids', value: removeData }];
	 Koala.ajax({
 		async:true,
 		type : "POST",
 		url: "<%=contextPath %>/preprocess-LogMessage-delete.action",
 		data:data,
 		dataType:'json',
 		success: function(data, textStatus){
  			 gridManager.deleteSelectedRow();
  			 gridManager.loadData();
 		}
 		});
}

</script>
</head>
<body>
<div style="width:98%;height:100%;padding-left: 5px;">
<!-- search form -->
<form name="searchForm" id="searchForm" target="_self">
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
<table width="800" border="0" style="margin:5px">
 <tr height="25px">
  <td width="12%">处理类型:</td>
  <td width="22%">
    <select name="logMessageDTO.executeType"  id="executeTypeID" class="select-common">
	  <option value="0">请选择</option>
	  <option value="3">处理出错</option>
	  <option value="2">处理结束</option>
	  <option value="1">开始处理</option>
	</select> 
  </td>
  <td width="12%">预处理:</td>
  <td width="22%">
    <select name="logMessageDTO.executeName"  id="executeNameID" class="select-common">
	 <option value="">--请选择--</option>
				<option value="官网和渠道差价的前五名">官网和渠道差价的前五名</option>
				<option value="每天官网和渠道航班的差价统计">每天官网和渠道航班的差价统计</option>
				<option value="实时价格处理">实时价格处理</option>
				<option value="统计历史最低价">统计历史最低价</option>
				<option value="统计往返历史最低价">统计往返历史最低价</option>
				<option value="生成航班信息">生成航班信息</option>
				<option value="运价监控">运价监控</option>
				<option value="舱位预警">舱位预警</option>
				<option value="价差预警">价差预警</option>
				<option value="竞价预警">竞价预警</option>
				<option value="实时往返价格处理">实时往返价格处理</option>
				<option value="南航国际报表">南航国际报表</option>
				<option value="南航国内报表">南航国内报表</option>
				<option value="南航淘宝价差">南航淘宝价差</option>
				<option value="深航报表">深航报表</option>
				<option value="国航国内OTA">国航国内OTA</option>
				<option value="国航国际OTA">国航国际OTA</option>
				<option value="国航淘宝旗舰代理价差">国航淘宝旗舰代理价差</option>
				<option value="元数据生成">元数据生成</option>
				<option value="当天元数据生成">当天元数据生成</option>
				<option value="往返元数据生成">往返元数据生成</option>
				<option value="当天往返元数据生成">当天往返元数据生成</option>
				<option value="航线最低价">航线最低价</option>
				<option value="汇率抓取入库">汇率抓取入库</option>
				<option value="航信元数据">航信元数据</option>
				<option value="航线抓取情况统计">航线抓取情况统计</option>
	</select> 
  </td>
  <td width="12%">时间:</td>
  <td colspan="3">
  	 <table border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><input type="text" name="logMessageDTO.executeStartTime" id="executeTimeID_start" ></td>
        <td width="15px">&nbsp;-&nbsp;</td>
        <td><input type="text" name="logMessageDTO.executeTimeEnd" id="executeTimeID_end" ></td>
      </tr>
    </table>
  	</td>
 </tr>
</table>	
</td>
    <td><input id="searchButton" type="button" class="btn-normal" onclick="searchAction()" value="查询" /></td>
  </tr>
</table>	
</form>
<!-- grid -->
<div id="maingrid"></div> 
</div>
</body>
</html>
